//normalni hra
    else if(stat == 1){
        if(rewrite_all){
            rewrite_all = false;
            
            Tft.fillRectangle(10,240,105,70,barvy[10]);
            Tft.fillRectangle(125,240,105,70,barvy[10]);
             
            Tft.drawString("SAVE", 27, 263, 3, BLACK); 
            Tft.drawString("MAIN", 142, 250, 3, BLACK);
            Tft.drawString("MENU", 142, 278, 3, BLACK);
        }
        if(rewrite_game){
            Tft.fillRectangle(10,10,220,220,BLACK);
            
            //zobrazeni jednotlivych dlazdic
            for(int x = 0; x < 4; x++){
                for(int y = 0; y < 4; y++){
                    Tft.fillRectangle(15+(x*54),15+(y*54), 49, 49, barvy[plocha[y][x]]);
                    if(plocha[y][x] != 0){
                        if(plocha[y][x] >= 10){
                            len = 0;  
                        }
                        else{
                            len = 10;
                        }  
                        
                        Tft.drawNumber(plocha[y][x], 19+(x*54)+len, 29+(y*54), 3, BLACK);
                    }
                }
            }
            rewrite_game = false;
        } 
        
        checkP();
        
        if(p.z > 10){
            
            //detekce dotyku v oblasti herni plochy
            if(p.x > 10 && p.x < 220 && p.y > 10 && p.y < 230){
                //smer nahoru
                if(p.x > p.y && p.x < -1*p.y + 240){
                    goUp();
                }
                
                //smer dolu
                else if(p.x < p.y && p.x > -1*p.y + 240){
                    goDown();
                }
                
                //smer doprava
                else if(p.x > p.y && p.x > -1*p.y + 240){
                    goRight();
                }
                
                //smer doleva
                else if(p.x < p.y && p.x < -1*p.y + 240){
                    goLeft();
                }
				do{
                    checkP();
                    delay(10);
                }while(p.z > 10);
                
                //kontrola konce hry
                gEnd = true; //nastavime na true a pokud nebude pravda, v@~@nasledujicim cyklu to zmenime
                for(int x = 0; x <= 3; x++){
                    for(int y = 0; y <= 3; y++){
                        if(plocha[y][x] == 0){
                            gEnd = false;
                        }
                        else if(x == 3 && y == 3){
                            //nic   
                            //u dolni prave dlazdice nic nekontrolujeme  
                        }
                        else if(x == 3){
                            if(plocha[y][3] == plocha[y+1][3] ){
                                gEnd = false;
                            }    
                        }
                        else if(y == 3){
                            if(plocha[3][x] == plocha[3][x+1]){
                                gEnd = false;
                            }
                        }
                        else{
                            //zbyla cast pole
                            if(plocha[y][x] == plocha[y][x+1] || plocha[y][x] == plocha[y+1][x]){
                                gEnd = false;
                            }
                        }
                    } 
                }
                
                //kontrola vyhry
                gWin = false;
                for(int x = 0; x <= 3; x++){
                    for(int y = 0; y <= 3; y++){
                        if(plocha[y][x] == 17){
                            gWin = true;    
                        }
                    }
                }
                
                //pokud se hnulo s bloky 
                if(moved){
                    moved = false;
                    rewrite_game = true;
                       
                    if(gEnd == false){
                        addTile();
                    }             
                }
                
                //rozhodnuti dalsiho postupu
                if(gEnd == true){
                    gEnd = false;
					stat = 2;                    
                    
                    rewrite_all = true;
                    rewrite_game = true;
                }  
                else if(gWin == true){
                    gWin = false;
                    
                    stat = 3;
                    
                    rewrite_all = true;
                    rewrite_game = true;
                }
                
                rewrite_game = true;    
            }
            
            //dolni cast herni plochy s tlacitky
            else if(p.y > 240 && p.y < 310){
                
                //tlacitko SAVE
                if(p.x > 10 && p.x < 115){
                    Tft.fillRectangle(20,95,200,100, barvy[17]);
                    
                    //ukladani
                    if(SD.exists("G2048.TXT")){
                        SD.remove("G2048.TXT"); //vycistime pripadny stary soubor
                    }
                    soubor = SD.open("G2048.TXT", FILE_WRITE);
                        
                    //pokud se otevreni povedlo, zapiseme hodnoty
                    if(soubor){
                        for(int y = 0; y <=3; y++){
                            for(int x = 0; x <= 3; x++){
                                soubor.write(plocha[y][x]);   
                            }
                        }
                        soubor.close();
                        Tft.drawString("SAVED", 28, 123, 6, BLACK);
                    }
                    else{
                        Tft.drawString("ERROR", 28, 123, 6, BLACK);
                    }
                        
                    delay(1000);
                    
                    rewrite_all = true;
                    rewrite_game = true;
                } 
                
                //tlacitko MAIN MENU
                else if(p.x > 125 && p.x < 210){
                    stat = 0;                    
                    rewrite_all = true;           
                }              
            }
        }
    }